package cn.pluss.baselibrary.base;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDexApplication;

import com.blankj.utilcode.util.Utils;
import com.hjq.toast.ToastUtils;
import com.litesuits.orm.db.DataBaseConfig;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import com.simple.spiderman.SpiderMan;

public class BaseApp extends MultiDexApplication {

    public static BaseApp instance;
    public static final String DB_NAME = "kerui_DB";

    @Override
    public void onCreate() {
        super.onCreate();
        SpiderMan.init(this);
//        if (LeakCanary.isInAnalyzerProcess(this)) {
//            // This process is dedicated to LeakCanary for heap analysis.
//            // You should not init your app in this process.
//            return;
//        }
        Utils.init(this);
        ToastUtils.init(this);
        instance = this;
        initDataBase();
//        LeakCanary.install(this);
        Logger.addLogAdapter(new AndroidLogAdapter());
    }

    private void initDataBase() {
        DataBaseConfig dataBaseConfig = new DataBaseConfig(instance);
        //数据库名，可设置存储路径。默认在内部存储位置databases文件夹下
        dataBaseConfig.dbName = DB_NAME;
        dataBaseConfig.debugged = true; //是否打Log
        dataBaseConfig.dbVersion = 1; // database Version
        dataBaseConfig.onUpdateListener = null; //升级

        //BaseDataBaseManager.init(dataBaseConfig);
    }

    public static Application getApplication() {
        return instance;
    }

    public static Context getAppContext() {
        return instance.getApplicationContext();
    }
}
